/*
 * EZCP_Sim_Threads.c
 *
 *  Created on: Apr 21, 2011
 *      Author: Group 8
 */

#include "EZCP_Sim_Common.h"

unsigned int MSG_DATA_LENGTHS [EZCP_NUM_OF_MSGS] =
{1, 1, 1, 4, 2, 4, 2, 2, 1, 121, 9, 3, 1, 1, 1, 1, 1, 9};

void *pf_Sender();
void *pf_Receiver();
void JoinThreads();
int CreateThreads ();
extern void initWidgetArrays ();

pthread_t	Sender_thread_id;
pthread_t	Receiver_thread_id;

int CreateThreads ()
{
	s32 si_RetVal=EXIT_SUCCESS;

	initWidgetArrays ();

	print("%s: Creating Sender and Receiver threads...\n",__func__);

	//start Simulator receiving thread (for actuators and support system)
	si_RetVal = pthread_create(&Receiver_thread_id, NULL, &pf_Receiver, NULL);
	if (EOK != si_RetVal) {
		print ("Could not create receiver thread\n");
		return si_RetVal;
	}

	//Start Simulator sending thread (for sensors)
	si_RetVal = pthread_create(&Sender_thread_id, NULL, &pf_Sender , NULL);
	if (EOK != si_RetVal) {
		print ("Could not create sender thread\n");
		return si_RetVal;
	}

	return si_RetVal;
}

void JoinThreads()
{
	print("%s: Waiting to join Sender and Receiver threads...\n",__func__);

	pthread_join (Sender_thread_id, NULL);
	pthread_join (Receiver_thread_id, NULL);

	return;
}


